package com.company.woye.onpackage.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.company.woye.R;
import com.company.woye.onpackage.entity.BoxInfpEntity;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class OnPackageDetailBoxAdapter extends BaseAdapter {

    private LayoutInflater inflater;
    private List<BoxInfpEntity> listSonEntities;

    public OnPackageDetailBoxAdapter(Context context, List<BoxInfpEntity> listEntities) {
        this.inflater = LayoutInflater.from(context);
        this.listSonEntities = listEntities;
    }

    @Override
    public int getCount() {
        return listSonEntities.size();
    }

    @Override
    public Object getItem(int position) {
        return listSonEntities.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHodler = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.on_package_box_detail_list_group, parent, false);
            viewHodler = new ViewHolder(convertView);
            convertView.setTag(viewHodler);
        } else {
            viewHodler = (ViewHolder) convertView.getTag();
        }
        if (listSonEntities.size()>0){
            if (!TextUtils.isEmpty(listSonEntities.get(position).getOutState())){
                viewHodler.tvChukuzhuangtai.setText(listSonEntities.get(position).getOutState());
            }
            viewHodler.tvWuliaoleixing.setText(listSonEntities.get(position).getMaterielType());
            viewHodler.tvXuhao.setText(listSonEntities.get(position).getRowNo());
            viewHodler.tvZhouzhuanxiang.setText(listSonEntities.get(position).getBoxNo());
        }
        return convertView;
    }



    class ViewHolder {
        @BindView(R.id.tv_xuhao)
        TextView tvXuhao;
        @BindView(R.id.tv_zhouzhuanxiang)
        TextView tvZhouzhuanxiang;
        @BindView(R.id.tv_wuliaoleixing)
        TextView tvWuliaoleixing;
        @BindView(R.id.tv_chukuzhuangtai)
        TextView tvChukuzhuangtai;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
